﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.GridRenderer
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

using System.Numerics;
using UnityEngine;

#nullable disable
namespace Netick.Unity;

public class GridRenderer : NetworkEventsListener
{
  private void OnDrawGizmos()
  {
    if (!((UnityEngine.Object) this.Sandbox != (UnityEngine.Object) null) || this.Sandbox.Engine == null || this.Sandbox.Engine.InterestManagement == null || !this.Sandbox.IsVisible || !this.Sandbox.Config.EnableInterestManagement || this.Sandbox.Config.RenderedLayer > this.Sandbox.Config.AoILayerCount - 1)
      return;
    AreaOfInterestLayer aoIlayer = this.Sandbox.Engine.InterestManagement.AoILayers[this.Sandbox.Config.RenderedLayer];
    float cellSize = (float) aoIlayer.CellSize;
    for (int index1 = 0; index1 < aoIlayer.CellsCountPerRowX; ++index1)
    {
      for (int index2 = 0; index2 < aoIlayer.CellsCountPerRowY; ++index2)
      {
        for (int index3 = 0; index3 < aoIlayer.CellsCountPerRowZ; ++index3)
        {
          Gizmos.color = new Color((float) byte.MaxValue, 0.0f, 0.0f, 0.7f);
          Gizmos.DrawWireCube(this.From(aoIlayer.Cells[index1, index2, index3].Position) + new Vector3(1f, 1f, 1f) * (float) aoIlayer.CellSize / 2f, new Vector3(1f, 1f, 1f) * (float) aoIlayer.CellSize * 0.95f);
        }
      }
    }
    if (!this.Sandbox.IsClient)
      return;
    foreach (InterestManagementGroup interestGroup in this.Sandbox.Engine.ClientSimulation.InterestGroups)
    {
      Gizmos.color = new Color(0.0f, (float) byte.MaxValue, 0.0f, 0.8f);
      Gizmos.DrawWireCube(interestGroup.Position.FromNumerics() + new Vector3(1f, 1f, 1f) * cellSize / 2f, new Vector3(1f, 1f, 1f) * cellSize * 0.91f);
    }
  }

  private Vector3 From(Vector3 from) => new Vector3(from.X, from.Y, from.Z);
}
